package modelLayer;

import java.util.ArrayList;

public class LoanContainer {
    
    private ArrayList<Loan> loans;
    private static LoanContainer instance;
    
    private LoanContainer() {
        loans = new ArrayList<Loan>();
    }
    
    public static LoanContainer getInstance() {
        if (instance == null) {
            instance = new LoanContainer();
        }
        
        return instance;
    }
    
    public void addLoan(Loan loan) {
        loans.add(loan);
    }
    
    public Loan findLoan(int id) {
        boolean found = false;
        int index = 0;
        while(index < loans.size() && !found) {
            Loan l = loans.get(index);
            if(l.getId() == id) {
                found = true;
            }
            else {
                index++;
            }
        }
        
        if(found) {
            return loans.get(index);
        }
        else {
            return null;
        }
    }
    
    public void removeLoan(Loan l) {
        loans.remove(l);
    }
}
